<template>
    <div id="trend">
        <div class="line-chart"></div>
    </div>
</template>

<script>
import {getQuickReportTrend } from '@/api/reportStatistics/index.js'
import * as echarts from 'echarts';
require('echarts/theme/macarons') // echarts theme
export default {
    data() {
        return {

        }
    },
    props: {
        time: {
            type: Object,
            default: {},
        },
        type: {
            type: String,
            default: '1',
        }
    },
    watch: {
        time(val) {
            this.getDeviceType()
        },
    },
    mounted() {
        // this.init()
        this.getDeviceType()
    },
    methods: {
        init(data,dom) {
            let option = {
                title: {
                    text:this.type=='1'? '国内地震数量趋势':'国外地震数量趋势',
                    textStyle: {
                        color: '#fff',}
                },
                legend: {
                    data: ['地震数量'],
                    textStyle: {
                        color: '#fff'
                    },
                    right: '7%',
                },
                grid: {
                    x: '12%',
                    width: '82%',
                    top: '20%',
                    bottom:'10%'
                },
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'shadow'
                    }
                },
                xAxis: {
                    type: 'category',
                    boundaryGap: false,
                    data: data.xData,
                    axisLine: {
                        lineStyle: {
                            color: '#F1F1F1'
                        }
                    },
                    axisTick: {
                        show: true,
                    },
                    axisLabel: {
                        color: '#fff',
                        showMaxLabel: true,
                    },
                    splitLine: {
                        show: false,
                    },
                },
                yAxis: {
                    name: '',
                    nameTextStyle: {
                        color: '#ffff'
                    },
                    axisTick: { show: true },
                    splitLine: {
                        show: true,
                        lineStyle: {
                            color: '#F1F1F1'
                        }
                    },
                    axisLine: {
                        lineStyle: {
                            color: '#F1F1F1',
                        }
                    },

                    axisLabel: {
                        color: '#fff',
                        formatter: '{value} ',
                    }
                },

                series: {
                    name: '地震数量',
                    type: 'line',
                    smooth: true,
                    symbol: 'none',
                    itemStyle: {
                        normal: {
                            color: this.type=='1'?'#29BB9D':'#FFC53D'
                        },
                    },
                    areaStyle: { //区域填充样式
                        normal: {
                            //线性渐变，前4个参数分别是x0,y0,x2,y2(范围0~1);相当于图形包围盒中的百分比。如果最后一个参数是‘true’，则该四个值是绝对像素位置。
                            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                offset: 0,
                                color: "rgba(41, 187, 157, 0.17)"
                            },
                            {
                                offset: 1,
                                color: "rgba(41, 187, 157, 0)"
                            }
                            ], false),
                            shadowColor: 'rgba(25,163,223, 0.5)', //阴影颜色
                            shadowBlur: 20 //shadowBlur设图形阴影的模糊大小。配合shadowColor,shadowOffsetX/Y, 设置图形的阴影效果。
                        }
                    },
                    data:data.yData
                }
            };
            dom.setOption(option)
        },
        async getDeviceType() {
            if (this.type == '1') {
                this.time.country  = '中国'
                const res = await getQuickReportTrend(this.time);
                if (res.code == 200) {
                    let dom = echarts.init(document.getElementsByClassName('line-chart')[0]);
                    this.init(res.data, dom);
                }
                return
            }
            this.time.country  = '国外'
            const res = await getQuickReportTrend(this.time);
            if (res.code == 200) {
                let dom = echarts.init(document.getElementsByClassName('line-chart')[1]);
                this.init(res.data, dom);
            }
        },
    }
}
</script>

<style lang='scss' scoped>
#trend {
    width: 100%;
    height: 240px;
    box-sizing: border-box;

    .line-chart {
        width: 100%;
        height: 100%;
    }
}
</style>